package com.ftg.learn.day16.javabase;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * Configuration会把当前这个java做为 类似于xml的功能的一个类
 *
 * @author 布衣
 * @Bean
 */
@Configuration
public class SpringConfiguration {
    /**
     * @return <bean id = 'initGoods' class="com.ftg.learn.day16.Goods">
     * <property name="id" value="" />
     * </bean>
     * @Bean 用来修饰一个方法 ，表示把这个方法的返回值 ，做为组件注入到注册表里面
     */
    @Bean
    public Goods initGoods() {
        Goods g = new Goods();
        g.setId(1001);
        g.setGoodName("康师傅方便面");
        g.setSupplier(this.initSupplier());
        return g;
    }

    @Bean
    public Supplier initSupplier() {
        Supplier s = new Supplier();
        s.setSupplierName("哈西");
        s.setSupplierAddress("aaaa");
        return s;
    }

    @Bean
    @Primary
    public Goods initGoods1() {
        Goods g = new Goods();
        g.setId(1002);
        g.setGoodName("李师傅方便面");
        g.setSupplier(this.initSupplier());
        return g;
    }

}
